package com.codingvip.tree;

/**
 * @author hansongtao
 */
public class BinaryTree {
    /**
     * 根结点
     */
    private CodeNode root;
    public BinaryTree() {
        root = null;
    }
    public CodeNode getRoot() {
        return root;
    }
    public CodeNode getParent(CodeNode currentNode) {
       return getParent(root, currentNode);
    }



    private CodeNode getParent(CodeNode root, CodeNode currentNode) {
        if (root == null) {
            return null;
        }
        if (root.getLeft() == currentNode|| root.getRight()==currentNode) {
            return root;
        }
        if (root.getLeft() != null) {
            getParent(root.getLeft(), currentNode);
        }

        return null;

    }

    public void setRoot(CodeNode root) {
        this.root = root;
    }
}
